\defmodule {NegativeBinomialGen}

This class implements random variate generators having the 
{\em negative binomial\/} distribution. Its mass function is
\begin{htmlonly}
\eq
   p(x) = \Gamma (\gamma + x) / (x!\: \Gamma (\gamma))\: p^\gamma (1 - p)^x,
    \qquad\mbox{for } x = 0, 1, 2, \ldots\label{eq:fmass-negbin}
\endeq
\end{htmlonly}
\begin{latexonly}
\eq
   p(x) = \frac{\Gamma(\gamma + x)}{x!\: \Gamma (\gamma)}\: p^\gamma (1 - p)^x,
    \qquad\mbox{for } x = 0, 1, 2, \ldots \label{eq:fmass-negbin}
\endeq
\end{latexonly}
where $\Gamma$ is the gamma function, 
$\gamma > 0$ and $0\le p\le 1$.
No local copy of the parameters $\gamma$ and $p$ is maintained in this class.
The (non-static) \texttt{nextInt} method simply calls \texttt{inverseF} on the
distribution.


\bigskip\hrule

\begin{code}
\begin{hide}
/*
 * Class:        NegativeBinomialGen
 * Description:  random variate generators for the negative binomial distribution
 * Environment:  Java
 * Software:     SSJ 
 * Copyright (C) 2001  Pierre L'Ecuyer and Universite de Montreal
 * Organization: DIRO, Universite de Montreal
 * @author       
 * @since

 * SSJ is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License (GPL) as published by the
 * Free Software Foundation, either version 3 of the License, or
 * any later version.

 * SSJ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * A copy of the GNU General Public License is available at
   <a href="http://www.gnu.org/licenses">GPL licence site</a>.
 */
\end{hide}
package umontreal.iro.lecuyer.randvar;\begin{hide}
import umontreal.iro.lecuyer.rng.*;
import umontreal.iro.lecuyer.probdist.*;
\end{hide}

public class NegativeBinomialGen extends RandomVariateGenInt \begin{hide} {
   protected double gamma;
   protected double p; 
\end{hide}
\end{code}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection* {Constructors}
\begin{code}

   public NegativeBinomialGen (RandomStream s, double gamma, double p) \begin{hide} {
      super (s, new NegativeBinomialDist (gamma, p));
      setParams (gamma, p);
   }\end{hide}
\end{code}
\begin{tabb} 
  Creates a negative binomial random variate generator with parameters
  $\gamma = $ \texttt{gamma} and $p$,  using stream \texttt{s}.
 \end{tabb}
\begin{code}

   public NegativeBinomialGen (RandomStream s, NegativeBinomialDist dist) \begin{hide} {
      super (s, dist);
      if (dist != null)
         setParams (dist.getGamma(), dist.getP());
   }\end{hide}
\end{code}
\begin{tabb} 
 Creates a new generator for the distribution \texttt{dist}, using 
  stream \texttt{s}.
 \end{tabb}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection* {Methods}
\begin{code}
    
   public static int nextInt (RandomStream s, double gamma, double p) \begin{hide} {
      return NegativeBinomialDist.inverseF (gamma, p, s.nextDouble());
   }\end{hide}
\end{code}
\begin{tabb}
 Generates a new variate from the {\em negative binomial\/} distribution,
 with parameters $\gamma = $~\texttt{gamma} and $p = $~\texttt{p},
 using stream \texttt{s}.
\end{tabb}
\begin{code}

   public double getGamma()\begin{hide} {
      return gamma;
   }\end{hide}
\end{code}
\begin{tabb} Returns the parameter $\gamma$ of this object.
\end{tabb}
\begin{code}

   public double getP()\begin{hide} {
      return p;
   }\end{hide}
\end{code}
\begin{tabb} Returns the parameter $p$ of this object.
\end{tabb}
\begin{hide}\begin{code}

   protected void setParams (double gamma, double p) {
      if (p < 0.0 || p > 1.0)
         throw new IllegalArgumentException ("p not in [0, 1]");
      if (gamma <= 0.0)
         throw new IllegalArgumentException ("gamma <= 0");
      this.p = p;
      this.gamma = gamma;
   }
\end{code}
\begin{tabb} Sets the parameter $\gamma$ and $p$ of this object.
\end{tabb}
\begin{code}
}\end{code}
\end{hide}
